package com.ming.sportdemo.controller;

import com.ming.sportdemo.config.ServerConfig;
import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

// 配置类 注入port的值
@Configuration
@ConfigurationProperties(prefix = "server")
class PortConfig {
    @Getter
    @Setter
    private int port;
}

@RestController
public class ServerController {

    // 或者使用@Value方式注入
    @Value("${server.port}")
    private int port;

    // 依赖配置
    @Autowired
    private ServerConfig serverConfig;

    @GetMapping("/test")
    public void test(){
        System.out.println(port);
        System.out.println(serverConfig.getPort());
    }
}

